﻿#region Copyright (C) Sector7 Software Studio. All rights reserved
/*******************************************************************************************
 * Creation
 *      Author:         Wolf Lai
 *      Date:           2013/2/18 星期一 23:55:57
 *      Version:        
 * Modification 
 *      Author: 
 *      Date: 
 *      Description: 
 *      Version:
 *******************************************************************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;
using System.Reflection;

namespace Sector7.Framework.Core
{
    /// <summary>
    /// 实体类基类
    /// </summary>
    [Serializable()]
    [DataContract]
    public class EntityBase : INotifyPropertyChanged
    {
        #region Events
        /// <summary>
        /// 属性改变事件
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged = null;
        #endregion

        #region Accessor
        #endregion

        #region Public functions
        #endregion

        #region Private functions
        /// <summary>
        /// 触发属性改变事件
        /// </summary>
        /// <param name="propertyName">发生改变的属性名称</param>
        protected void OnPropertyChanged(string propertyName)
        {
            PropertyInfo property = this.GetType().GetProperty(propertyName);
            object propertyValue = null;

            switch (property.PropertyType.Name)
            {
                case "String":
                    propertyValue = property.GetValue(this, null);
                    if (propertyValue != null)
                        property.SetValue(this, propertyValue.ToString().Trim(), null);
                    break;
                default:
                    break;
            }

            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}
